package com.yechaoa.pictureselectordemo;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.yechaoa.pictureselectordemo.db.DataManager;
import com.yechaoa.pictureselectordemo.db.SuceptorOperationHistory;
import com.yechaoa.pictureselectordemo.viewholder.RAdapter;
import com.yechaoa.pictureselectordemo.viewholder.RSingleDelegate;
import com.yechaoa.pictureselectordemo.viewholder.use.SusceptorHistoryListViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HistoryActivity extends BaseActivity {

    private List<SuceptorOperationHistory> historyList = new ArrayList<SuceptorOperationHistory>();
    private RAdapter<SuceptorOperationHistory> adapter;

    @BindView(R.id.tv_his_at_empty)
    TextView tv_his_at_empty;

    @BindView(R.id.rv_history_list)
     RecyclerView rvHistoryList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_history);
        //绑定处理
        ButterKnife.bind(this);
//        Toolbar toolbar = findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//        if (getSupportActionBar() != null) {
//            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//            getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_back);
//            getSupportActionBar().setTitle("返回");
//        }

//        ActionBar actionBar = getActionBar();
//        // 显示返回按钮
//        actionBar.setDisplayHomeAsUpEnabled(true);
//        // 去掉logo图标
//        actionBar.setDisplayShowHomeEnabled(false);
//        actionBar.setTitle("返回");

//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);
//
//        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//        fab.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
//                        .setAction("Action", null).show();
//            }
//        });

        adapter = new RAdapter<>(historyList, new RSingleDelegate<>(SusceptorHistoryListViewHolder.class));
        rvHistoryList.setLayoutManager(new LinearLayoutManager(this));
        rvHistoryList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        rvHistoryList.setAdapter(adapter);
    }
    @Override
    protected void onResume() {
        super.onResume();
        refreshList();
    }

    private void refreshList() {
        List<SuceptorOperationHistory> _historyList = DataManager.getInstance().getHistoryList();
        this.historyList.clear();
        this.historyList.addAll(_historyList);
        adapter.notifyDataSetChanged();
        tv_his_at_empty.setVisibility(this.historyList.isEmpty() ? View.VISIBLE : View.GONE);
    }
}
